﻿using Application.Cache;
using AutoMapper;
using Domain.Event;
using Domain.IRepositorys;
using Domain.Model;
using Domain.Services;
using Domain.Types;
using Infrastructure.DomainEvent;
using Infrastructure.Error;
using Infrastructure.UniOfWorkBase;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Application.Event
{
    /// <summary>
    /// 全局收支记录
    /// </summary>
    public class CloseTaskEventHandler : IDomainEventHandler<CloseTaskEvent>
    {
        public ITaskRepository taskRepository { get; set; }
        public ITaskTakeRepository taskTakeRepository { get; set; }
        public TaskDetailsCache taskDetailsCache { get; set; }
        public IEFUnitOfWork efUnitOfWork { get; set; }
        public TaskService  taskService { get; set; }
        public ILogger<CloseTaskEventHandler> _logger { get; set; }
        public override Task HandleAysnc(CloseTaskEvent domainEvent, CancellationToken cancellationToken = default)
        {
            if (taskService.TaskFinishDo(domainEvent.TaskID))
            {
                //如果结束了就删除缓存
                taskDetailsCache.RemoveCache(domainEvent.TaskID);
            }

            return Task.CompletedTask;
        }
    }
}
